const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    userInfo:{},
    currentData: 0, 
    selectPerson: true,
    playerresult:[],
    currentseletyear:new Date().getFullYear(),
    playerinfo:{},
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },
  onShow:function(){
    this.setData({userInfo:app.globalData.userInfo});
    this.getdate();
  },
 
  //获取当前滑块的index
  bindchange: function(e) {
    const that = this;
    that.setData({
      currentData: e.detail.current
    })
  },
  
  
  //点击切换，滑块index赋值
  checkCurrent: function(e) {
    const that = this;

    if (that.data.currentData === e.target.dataset.current) {
      return false;
    } else {

      that.setData({
        currentData: e.target.dataset.current
      })
    }
  },
  onIpItemClick: function (event) {
    console.log(event);
    var index = event.currentTarget.dataset.index;
    var year = this.data.playerinfo.yearlists[index];
      this.setData({
      currentData:index,
      currentseletyear:year,
    });
    this.getdate();
  },
  getdate(){
    wx.showLoading({
      title: '正在加载',
    });
    console.log(this.data.userInfo);
    var that = this;
     app.getplayerInfo(this.data.userInfo.player_id,this.data.currentseletyear,1,function(res){
         if(res.data.data){
          that.setData({playerinfo:res.data.data})
         }
         else{
           that.setData({playerinfo:[]})
         }
     },function(){
       wx.hideLoading();
     });
  },

  openscorecard(e){
        var match = e.currentTarget.dataset.match;
        console.log(match);
        var that = this;
        console.log(that.data.playerinfo);
        wx.navigateTo({
          url: '../../Scorecard/player/index?selectid='+that.data.playerinfo.playerID + "&playername="+that.data.playerinfo.playername+"&matchid="+match.matchid,
           success: function(res) {
            // 通过eventChannel向被打开页面传送数据
            res.eventChannel.emit('acceptDataFromOpenerPage', { match: match,playerid:that.data.playerinfo.player_id,playername:that.data.playerinfo.playername })
          }
      });
  },
  
})